// /**
//  * Created by Luji on 2017/4/18.
//  */
import './images.scss';
import temp from './images.html';
import ctrl from './images.ctrl.js';


export default angular.module('ctg-k8sconsole').config(['$stateProvider', $stateProvider=> {
    $stateProvider.state('my-image', {
        url: '/my/image',
        templateUrl: temp,
        controller: ctrl,
        controllerAs: 'list',
        resolve: {
            list: ['imageSrv', 'ctgNotification','$rootScope', function (imageSrv, ctgNotification,$rootScope) {
                return imageSrv.getHarborImages({currentPage: 1,sysUserCode:JSON.parse(localStorage.getItem('myUser')).sysUserCode,imageType:$rootScope.imageType?$rootScope.imageType:'001'}).catch(function (data) {
                    ctgNotification.error('获取我的镜像列表数据有误.');
                });
            }],
            versions:['list' ,'imageSrv', 'ctgNotification','$rootScope', function (list, imageSrv, ctgNotification,$rootScope) {
                if(list){
                    angular.forEach(list.list, (img)=>{
                       imageSrv.getHarborVersions(img.imageName,$rootScope.imageType?$rootScope.imageType:'001').then(data=> {
                            img.versions = data;
                        }).catch(function (data) {
                            ctgNotification.error('获取我的镜像版本数据有误.');
                        });
                    })
                }
            }]
        }
    })
}]);
